package org.example.view.Frame;

import org.example.view.componet.ATMButton;
import org.example.view.componet.BackgroundScene;
import org.example.view.componet.ButtonTypeEnum;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;


/**
 * 选择菜单页面
 */
public class ChooseAtm extends JPanel {
    /**
     * 背景
     */
    private BackgroundScene backgroundScene;

    /**
     * 退出按钮
     */
    private ATMButton offButton;

    /**
     * 改密按钮
     */
    private ATMButton modifyButton;

    /**
     * 查询按钮
     */
    private ATMButton findButton;

    /**
     * 存款按钮
     */
    private ATMButton saveButton;

    /**
     * 取款按钮
     */
    private ATMButton getButton;

    /**
     * 对话框
     */
    private JLabel pane;

    /**
     * 对话
     */
    private JLabel textPane;

    public ChooseAtm(JPanel panel) {
        this.addContent(panel);
    }

    private void addContent(JPanel panel) {
        this.setLayout(null);

        /**
         * 退出按钮（退出程序）
         */
        this.offButton = new ATMButton(ButtonTypeEnum.退出, 450, 650);
        this.offButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        this.add(this.offButton);

        /**
         * 改密按钮（跳转改密页面）
         */
        this.modifyButton = new ATMButton(ButtonTypeEnum.改密, 20, 245);
        this.modifyButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "modify");
            }
        });
        this.add(this.modifyButton);

        /**
         * 查询按钮（跳转查询页面）
         */
        this.findButton = new ATMButton(ButtonTypeEnum.查询, 20, 345);
        this.findButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "find");
            }
        });
        this.add(this.findButton);

        /**
         * 存款按钮（跳转存款页面）
         */
        this.saveButton = new ATMButton(ButtonTypeEnum.存款, 855, 245);
        this.saveButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "save");
            }
        });
        this.add(this.saveButton);

        /**
         * 取款按钮（跳转取款页面）
         */
        this.getButton = new ATMButton(ButtonTypeEnum.取款, 855, 345);
        this.getButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "save");
            }
        });
        this.add(this.getButton);

        /**
         * 操作提示
         */
        this.textPane = new JLabel();
        this.textPane.setText("请选择业务");
        this.textPane.setFont(new Font("宋体",Font.ITALIC, 50));
        this.textPane.setForeground(Color.WHITE);
        this.textPane.setBounds(245, 245, 305, 170);
        this.add(this.textPane);

        /**
         * 操作框
         */
        this.pane = new JLabel(new ImageIcon("/Users/cengyunke/Desktop/atm1/ATMGUI/src/main/java/org/example/img/pane.jpg"));
        this.pane.setBounds(210, 250, 620, 200);
        this.add(this.pane);

        /**
         * 背景
         */
        this.backgroundScene = new BackgroundScene();
        this.add(this.backgroundScene);

    }


}
